package model.stats;

import java.util.Iterator;
import java.util.LinkedList;

/**
 * 
 * This class applies modifications to the StatsContanier that are persistent, that is
 * they are permanent until explicitly removed. The applies method adds the modifiers
 * to the stats, the remove method subtracts the same value from the stats. Before 
 * applying to stats, the modifiers have to be defined. An addXXXMod method loads a new
 * modifier that will be applied to XXX stat. All the modifiers have to be loaded before 
 * the StatsPersistMods is applied(). 
 * @author dkorytov
 * 
 */

public class StatsPersistMods {
	
	LinkedList<PersistModifier> modifiers = new LinkedList<PersistModifier>();
	
	public StatsPersistMods(){}
	/**
	 * Adds the loaded modifiers to the statsContianer
	 * @param stats
	 */
	public void apply(StatsContainer stats){
		Iterator<PersistModifier> iter = modifiers.iterator();
		while(iter.hasNext()){
			iter.next().add(stats);
		}
	}
	/**
	 * Removed the loaded modifiers from the statsContainer. 
	 * @param stats
	 */
	public void remove(StatsContainer stats){
		Iterator<PersistModifier> iter = modifiers.iterator();
		while(iter.hasNext()){
			iter.next().remove(stats);
		}
	}
	
	public void addStrengthMod(Integer amount){
		modifiers.add(
			new PersistModifier(){
				public void apply(StatsContainer container, int magnitude){
					container.addPersistModStrength(magnitude);
				}
			}
		);
	}
	public void addAgilityMod(Integer amount){
		modifiers.add(
				new PersistModifier(){
					public void apply(StatsContainer container, int magnitude){
						container.addPersistModAgility(magnitude);
					}
				}
			);
	}
	public void addIntellectMod(Integer amount){
		modifiers.add(
				new PersistModifier(){
					public void apply(StatsContainer container, int magnitude){
						container.addPersistModIntellect(magnitude);
					}
				}
			);
	}
	public void addHardinessMod(Integer amount){
		modifiers.add(
				new PersistModifier(){
					public void apply(StatsContainer container, int magnitude){
						container.addPersistModHardiness(magnitude);
					}
				}
			);
	}
	public void addMovmentMod(Integer amount){
		modifiers.add(
				new PersistModifier(){
					public void apply(StatsContainer container, int magnitude){
						container.addPersistModMovement(magnitude);
					}
				}
			);
	}
	public void addMaxHealthMod(Integer amount){
		modifiers.add(
				new PersistModifier(){
					public void apply(StatsContainer container, int magnitude){
						container.addPersistModMaxHealth(magnitude);
					}
				}
			);
	}
	public void addMaxManaMod(Integer amount){
		modifiers.add(
				new PersistModifier(){
					public void apply(StatsContainer container, int magnitude){
						container.addPersistModHardiness(magnitude);
					}
				}
			);
	}
	public void addOffenseMod(Integer amount){
		modifiers.add(
				new PersistModifier(){
					public void apply(StatsContainer container, int magnitude){
						container.addPersistModOffense(magnitude);
					}
				}
			);
	}
	public void addDefenseMod(Integer amount){
		modifiers.add(
				new PersistModifier(){
					public void apply(StatsContainer container, int magnitude){
						container.addPersistModDefense(magnitude);
					}
				}
			);
	}
	public void addArmorMod(Integer amount){
		modifiers.add(
				new PersistModifier(){
					public void apply(StatsContainer container, int magnitude){
						container.addPersistModArmor(magnitude);
					}
				}
			);
	}
	public void addVisionMod(Integer amount){
		modifiers.add(
				new PersistModifier(){
					public void apply(StatsContainer container, int magnitude){
						container.addPersistModIntellect(magnitude);
					}
				}
			);
	}
}
